<template>
    <div class="wrap">
        <group title="选择您将查看的企业">
            <cell-box v-for="(val,key) in companyList" :key="val.companyCode" is-link @click.native="nav(key)">
                {{val.companyName}}
            </cell-box>
        </group>
    </div>
</template>

<script>
import Vue from 'vue'
import store from '@/store/report/index'
import { Group, Cell,CellBox  } from 'vux'

import axios from '@/api/axios'
import api from '@/api/base.api'
import { mapState } from 'vuex'
export default {
    components: {
        Cell,
        CellBox,
        Group,
    },
    mounted() {
    },
    beforeRouteEnter(to, from, next) {
        // 在渲染该组件的对应路由被 confirm 前调用
        // 不！能！获取组件实例 `this`
        // 因为当钩子执行前，组件实例还没被创建
        //* 没有查询绑定信息之前
        if (store.state.companyList.length == 1) {
            var path = `/overView/${store.state.companyList[0].companyCode}/${store.state.companyList[0].holderCode}`;
            next(path);
        }
        //绑定且多个公司
        else if (store.state.companyList.length == 0) {
            next('/noCompany');
        } else {
            next();
        }
    },
    computed: {
        ...mapState({
            companyList: state => state.companyList
        })
    },
    methods: {
        nav(idx) {
            console.log(idx);
            this.$router.push(`/overView/${this.companyList[idx].companyCode}/${this.companyList[idx].holderCode}`)
        }
    }
}
</script>

<style lang="less">
h3 {
    text-align: center;
    font-size: 18px;
    margin: 100px auto 20px;
}

.body {
    height: 100%;
}
</style>